package com.gitee.wsl.mathematics.coordinate.polar

import com.gitee.wsl.ext.array.DoubleArray
import com.gitee.wsl.ext.number.mod
import com.gitee.wsl.io.dataproxy.DataGet
import com.gitee.wsl.io.dataproxy.asProxy
import com.gitee.wsl.mathematics.coordinate.PolarCoordinate
import com.gitee.wsl.mathematics.number.DoubleCalcContainer
import com.gitee.wsl.unit.angle.AngleUnit
import com.gitee.wsl.unit.angle.toDegrees


data class Polar(override val proxy: DataGet<Double> = DoubleArray(0.0,0.0).asProxy()
): PolarCoordinate<Double, Polar>,DoubleCalcContainer {
    constructor(radius: Double, theta: Double):this(DoubleArray(radius,theta).asProxy())
    constructor(radius: Number,  angle: AngleUnit):this(radius.toDouble(),angle.degrees)

    val radius get() = proxy[0]
    val radiusF get() = proxy[0].toFloat()

    val theta get()  = proxy[1]
    val thetaF get()  = proxy[1].toFloat()

    val angle: AngleUnit get() = proxy[1].toDegrees()

    override fun create(values: List<Double>)= Polar (values[0],values[1])

    override val squaredLength: Double get() = TODO()

    override val self: Polar
        get() = this

    /**
     * make a safe version by bringing [theta] between 0 and 360
     */
    fun makeSafe() = Polar(
        mod(theta, 360.0),
        radius
    )

     //operator fun plus(right: Polar) = Polar(theta + right.theta, radius + right.radius)
     //operator fun minus(right: Polar) = Polar(theta - right.theta, radius - right.radius)
     //operator fun times(scale: Polar) = Polar(theta * scale.theta, radius * scale.radius)

     operator fun times(scale: Double) = Polar(theta * scale, radius * scale)
     operator fun div(scale: Double) = Polar(theta / scale, radius / scale)

    companion object {}
}

